
module.exports = function ($scope, $state, $stateParams,$resource,$modal,items,$modalInstance,FileUploader, type, toaster) {
    console.log(items);
    $scope.item = items;
    $scope.type = type;
    console.log($scope.type);
    // 公告类型
    $scope.typeFileArr = [
        {name:'王者类型',value:'1', id : '1'},
        {name:'青铜',value:'2', id : '2'},
        {name:'白银',value:'3', id : '3'},
        {name:'王者类型1',value:'4', id : '4'},
        {name:'青铜1',value:'5', id : '5'},
        {name:'白银1',value:'6', id : '6'},
        {name:'王者类型2',value:'7', id : '7'},
        {name:'青铜2',value:'8', id : '8'},
        {name:'白银2',value:'9', id : '9'}        
    ]
    // 详情
    $scope.getInfo = function(){
        $resource('/api/as/ggc/reviewPlanning/findInfo', {}, {}).save({'project_code':items.project_code}, function(res){			              
            if(res.errcode === 0 || res.errcode === 10003){
                console.log(res);
                $scope.a = res.data;
                //返回的字符串变成数组
                // $scope.array = $scope.a.project_file.split(',');
                // console.log($scope.array);
                // for(var i = 0;i<$scope.array.length;i++){
                //     if($scope.array[i]==''){
                //         $scope.array.splice(i,1);
                //     }
                // }

                if($scope.a.city_project=='0'){
                    $scope.a.city_project='区县项目'
                } else if($scope.a.city_project=='1'){
                    $scope.a.city_project='市本级项目'
                } 
                if($scope.a.project_build=='0'){
                    $scope.a.project_build='建设类'
                } else if($scope.a.project_build=='1'){
                    $scope.a.project_build='非建设类'
                }
                if($scope.a.project_level=='0'){
                    $scope.a.project_level='国家'
                } else if($scope.a.project_level=='1'){
                    $scope.a.project_level='省'
                } else if($scope.a.project_level=='2'){
                    $scope.a.project_level='市'
                } 
                $scope.getProjecttType($scope.a.project_type);
                // 材料
                console.log('材料');
                console.log(JSON.parse($scope.a.project_file));
                $scope.material = JSON.parse($scope.a.project_file);
                if($scope.material.aa){
                  $scope.array1 = $scope.material.aa;
                } else {
                  $scope.array1 = undefined;
                }
                if($scope.material.bb){
                  $scope.array2 = $scope.material.bb;
                } else {
                  $scope.array2 = undefined;
                }
                $scope.array3 = $scope.material.cc;
                $scope.array4 = $scope.material.dd;
                $scope.array5 = $scope.material.ee;
                $scope.array6 = $scope.material.ff;
                $scope.array7 = $scope.material.gg;
                $scope.array8 = $scope.material.hh;
                $scope.array9 = $scope.material.ii;

            }else{
                alert(res.errmsg);
            }
        });
    }
    $scope.getInfo();
    $scope.getProjecttType = function(project_type){
        $scope.typeFileArr.forEach(element => {
          if(project_type == element.value){
            $scope.a.project_type = element.name;
          }
        });
    }
    $resource('/api/as/ggc/reviewGuide/findInfoTypeList', {}, {}).save({}, function(res){
        if(res.errcode === 0){                      
            // console.log(res);
            // console.log('上面是res');
            $scope.ntarr=[];
            for(var i =0;i<res.data.length;i++){
                $scope.ntarr.push({name:i,value:res.data[i].guide_type});
            }
            console.log($scope.ntarr);
        }else{
            alert(res.errmsg);
        }
    });
    $scope.del=function(index){
        $scope.array.splice(index,1);
        $scope.a.project_file=$scope.array.join(',');
    }
    $scope.image = function(){
        var para = $state.get('app.imageupload');
        //设置上传文件夹，以自己业务命名
        angular.extend(para, {
          resolve : {  
            'dir' : function(){
              return 't1';
            }
          } 
        })
        console.log(para);
        var modalInstance = $modal.open(para);
        modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
          console.log('modal is opened');  
        });  
        modalInstance.result.then(function(result) {  
          console.log(result);  
          $scope.imagearr = JSON.stringify(result);
          // console.log(scope.imagearr);
          $scope.array = result;
          $scope.a.project_file=$scope.array;
          // $scope.a.project_file = array[0];
          // console.log(scope.info.img);
          // form.result['templete_lock_data_json'] = JSON.stringify(result.lock);
          // form.result['templete_check_data_json'] = result.unlock;

        }, function(reason) {  
          console.log(reason);// 点击空白区域，总会输出backdrop  
          // click，点击取消，则会暑促cancel  
          $log.info('Modal dismissed at: ' + new Date());  
        }); 
    };   
    // 区县通过
    $scope.pass= function () {   
      if ($scope.type == '0'){
        $scope.flag = 'sjcstg';
          var modalInstance = $modal.open({
            template: require('../views/passInfo.html'),
            controller: 'passInfo',
            size: 'xs',
            resolve: {
                items: function () {
                    return items;
                },
                flag: function () {
                    return $scope.flag;
                },
            }
          });
          modalInstance.result.then(function (showResult) {	
            $modalInstance.close();
            $state.go('app.examine');
          });  
      } else if(type == '1') { //区县初审通过
          if(confirm('该项目是否通过初审？')){
            $resource('/api/as/ggc/reviewDistrictTourism/updateByRecommend', {}, {}).save({'project_code':items.project_code}, function(res){			              
                if(res.errcode === 0 || res.errcode === 10003){
                    toaster.success({title:"",body:'通过成功'});
                    $modalInstance.close();
                }else{
                    toaster.error({title:"",body:res.errmsg});
                }
            });
            $resource('/api/as/ggc/reviewPlanning/insertReviewCompanyProjectLog', {}, {}).save({'project_code':items.project_code, 'recommend_type' : $scope.a.recommend_type, 'check_city' : $scope.a.check_city, 'check_state' : '1'}, function(res){			              
                if(res.errcode === 0 || res.errcode === 10003){
                    console.log(res);
                }else{
                    alert(res.errmsg);
                }
            });
          }	
      }
    }
    // 区县驳回
    $scope.againPass= function () {  
        if ($scope.type == '0') {
            $scope.flag = 'sjbh';
        }  else if ($scope.type == '1') {
            $scope.flag = 'qxbh';
        }
        var modalInstance = $modal.open({
            template: require('../views/reject_info.html'),
            controller: 'reject_info',
            size: 'xs',
            resolve: {
                items: function () {
                    return items;
                },
                flag: function () {
                    return $scope.flag;
                },
                type: function () {
                    return $scope.type;
                },
            }
        });
        modalInstance.result.then(function (showResult) {	
          $modalInstance.close();
          $state.go('app.examine');
        });  	
    }
    // 区县淘汰
    $scope.eliminate= function () {  
      if ($scope.type == '0') {
          $scope.flag = 'sjtt';
      }  else if ($scope.type == '1') {
          $scope.flag = 'qxtt';
      }
        var modalInstance = $modal.open({
            template: require('../views/reject_info.html'),
            controller: 'reject_info',
            size: 'xs',
            resolve: {
                items: function () {
                    return items;
                },
                flag: function () {
                    return $scope.flag;
                },
                type: function () {
                    return $scope.type;
                },
            }
        });
        modalInstance.result.then(function (showResult) {	
            $modalInstance.close();
            $state.go('app.examine');
        });  
    }

    $scope.close = function(){
        $modalInstance.close();
    }
};
